package com.hzit.hzb.core.controller.api;


import com.hzit.common.result.R;
import com.hzit.hzb.base.util.JwtUtils;
import com.hzit.hzb.core.pojo.entity.BorrowInfo;
import com.hzit.hzb.core.service.BorrowInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author hbxfwf
 * @since 2024-08-27
 */
@RestController
@RequestMapping("/api/core/borrowInfo")
public class BorrowInfoController {

	@Autowired
	private BorrowInfoService borrowInfoService;

	//1. 保存借款信息
	@PostMapping("/auth/save")
	public R save(@RequestBody BorrowInfo borrowInfo, @RequestHeader("token") String token){
		// 1.1 获取userId
		Long userId = JwtUtils.getUserId(token);
		// 1.2 保存借款信息到数据库
		borrowInfoService.saveBorrowInfo(borrowInfo,userId);
		// 1.3 返回
		return R.ok().message("保存借款信息成功！");
	}

	//2. 获取用户申请状态值
	@GetMapping("/auth/getBorrowInfoStatus")
	public R getBorrowInfoStatus(@RequestHeader("token") String token){
		// 2.1 获取userId
		Long userId = JwtUtils.getUserId(token);
		// 2.2 根据用户id获取状态值
		Integer status = borrowInfoService.getBorrowInfoStatus(userId);
		// 2.3 返回
		return R.ok().data("borrowInfoStatus",status);
	}
}

